import { defineStore } from "pinia";
import { store } from "@/store";
import { expInsType } from "./types";

export const useExpInsStore = defineStore({
  id: "expIns",
  state: (): expInsType => ({
    isRuning: false,
    configPercentage: 0,
    formattedTime: "",
    labExperimentDatastate: 0,
    configId: "",
    expInstId: ""
  }),
  getters: {
    getIsRuning(state) {
      return state.isRuning;
    },
    getConfigPercentage(state) {
      return state.configPercentage;
    },
    getFormattedTime(state) {
      return state.formattedTime;
    },
    getLabExperimentDatastate(state) {
      return state.labExperimentDatastate;
    },
    getConfigId(state) {
      return state.configId;
    },
    getExpInstId(state) {
      return state.expInstId;
    }
  },
  actions: {
    CHANGE_SETTING({ key, value }) {
      if (Reflect.has(this, key)) {
        this[key] = value;
      }
    },
    changeSetting(data) {
      this.CHANGE_SETTING(data);
    }
  }
});

export function useExpInsHook() {
  return useExpInsStore(store);
}
